package com.hh.tax.controller;/*
 * @Auther:ZhengXueCheng
 * @Date:2023/8/2
 * @VERSON:1.8
 */

import com.hh.tax.service.TaxService;
import com.hh.tax.vo.AddTaxVo;
import com.hh.tax.vo.StatusChangeVo;
import com.hh.tax.vo.TaxVo;
import com.hh.tax.vo.UpdateTaxVo;
import com.hh.utils.ResultVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/tax")
@CrossOrigin
public class TaxController {

    @Autowired
    private TaxService taxService;

    @PostMapping("/queryPage")
    public ResultVo queryPage(@RequestBody TaxVo taxVo) {
        return taxService.findAllTaxByPage(taxVo);
    }

    @PostMapping("/save")
    public ResultVo save(@RequestBody AddTaxVo addTaxVo, BindingResult bindingResult) {
        if (bindingResult.hasErrors()) {
            return ResultVo.error(bindingResult.getFieldError().getDefaultMessage());
        }
        return taxService.addTax(addTaxVo);
    }

    @PostMapping("/updateStatus")
    public ResultVo updateStatus(@RequestBody StatusChangeVo statusChangeVo) {
        return taxService.updateStatus(statusChangeVo);
    }

    @PostMapping("/update")
    public ResultVo update(@RequestBody UpdateTaxVo updateTaxVo) {
        return taxService.updateTax(updateTaxVo);
    }
}
